//引入二次封装axios
import request from "@/utils/request";
//引入接口类型约束
import type { getAllMenuDataRespones, addOrEditMenuData } from "./type";
// 枚举接口
enum API {
  //获取全部菜单数据
  getAllMenu = "/admin/acl/permission",
  //给当前菜单添加一条子菜单
  ADDMENU_URL = "/admin/acl/permission/save",
  //修改菜单
  UPDATEMENU_URL = "/admin/acl/permission/update",
  //删除菜单
  DELETEMENU_URL = "/admin/acl/permission/remove/",
}

//获取全部菜单数据接口
export const getAllMenu = () =>
  request.get<any, getAllMenuDataRespones>(API.getAllMenu);
//添加子菜单或者修改菜单的回调
export const AddOrUpdateMenu = (data: addOrEditMenuData) => {
  if (data.id) {
    return request.put<any, any>(API.UPDATEMENU_URL, data);
  } else {
    return request.post<any, any>(API.ADDMENU_URL, data);
  }
};
//删除菜单的接口
export const reqDeleteMenu = (id: number) =>
  request.delete<any, any>(API.DELETEMENU_URL + id);
